package user

import (
	"cat-collage-backend/internal/model"
	"errors"
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
)

func GetUserInfo(c *gin.Context, db *gorm.DB) {
	userId, _ := c.GetPostForm("userId")
	if userId == "" {
		c.JSON(400, gin.H{"error": "Please provide user_id"})
		return
	}

	user := &model.User{}

	result := db.Where("id = ?", userId).First(&user)

	if errors.Is(result.Error, gorm.ErrRecordNotFound) {
		c.JSON(400, gin.H{"error": "User not found"})
		return
	}

	c.JSON(200, gin.H{"username": user.Username})
}
